import { createPinia } from 'pinia'
import { createApp } from 'vue'
import type { App } from 'vue'
import Root from './App.vue'
import {
  setupAccessDirective,
  setupLoadingDirective,
} from './directive'
import router from '@/router'
import '@/router/router-guard'
import 'ant-design-vue/dist/reset.css'
import '@/assets/styles/reset.css'
import 'uno.css'
import { useLoadingCheck } from '@/composables/loading'
// 移除对 H5 analysis.css 的全局引入，避免影响 Web 端
// import '@/h5/analysis.css'
import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn'

const pinia = createPinia()
async function start() {
  const app: App = createApp(Root)
  app.use(pinia)
  setupDirective(app)
  app.use(router)
  app.mount('#app')
  app.config.performance = true
  // 挂载完成后移除首次加载遮罩，避免偶发不关闭
  useLoadingCheck()
}

function setupDirective(app: App) {
  // 注册loading自定义指令
  setupLoadingDirective(app)
  setupAccessDirective(app)
}
start()
// 全局设置 dayjs 语言为中文
dayjs.locale('zh-cn')
